﻿using System;


using Business.Base.Model;
using Business.Base.Service;
using Microsoft.Office.Interop.Excel;
//using NPOI.SS.UserModel;

namespace Business.NPSH
{
    public  class NpshExperimentExcelManager : IExperimentExcelManager
    {

        public void setExcel(Experiment exp, Workbook wk)
        {
            Worksheet sheet = wk.Sheets[1];
            NpshExperiment experiment = (NpshExperiment)exp;

            sheet.Rows[1].Cells[1].Value = experiment.Customer + "水泵汽蚀测试报告";
           
            #region 第4行
            //试验编号
            sheet.Rows[3].Cells[3].Value = experiment.ExperimentCode;
            //额定流量
            sheet.Rows[3].Cells[6].Value = experiment.PumpRatedFlow;
            //产品名称
            sheet.Rows[3].Cells[9].Value = experiment.PumpName;
            #endregion

            #region 第5行
            //试验编号
            sheet.Rows[4].Cells[3].Value = experiment.PumpModel;
            //额定流量
            sheet.Rows[4].Cells[6].Value = experiment.PumpRatedHead;
            //产品名称
            sheet.Rows[4].Cells[9].Value = experiment.PumpRatedPower;
            #endregion

            #region 第5行
            //试验编号
            sheet.Rows[5].Cells[3].Value = experiment.MotorRatedSpeed;
            //额定流量
            sheet.Rows[5].Cells[6].Value = experiment.MotorRatedEfficiency;
            //产品名称
            sheet.Rows[5].Cells[9].Value = experiment.DInlet*1000;

            #endregion

            #region 第6行
            //试验编号
            sheet.Rows[6].Cells[3].Value = experiment.PumpRatedNpsh;;
            //额定流量
            //sheet.Rows[6].Cells[6].Value = experiment.DesignCriticalNpsh;
            //产品名称
            sheet.Rows[6].Cells[9].Value = experiment.DOutlet*1000;

            #endregion

            int rowIndex = 9;

            foreach (NpshExperimentRecord record in experiment.RecordList)
            {
                sheet.Rows[rowIndex + 1].Cells[1].Value  = (rowIndex - 9) + 1;
                sheet.Rows[rowIndex + 1].Cells[2].Value  =  Decimal.Round((Decimal)record.WorkingFlow, 2);
                sheet.Rows[rowIndex + 1].Cells[3].Value  =  Decimal.Round((Decimal)record.PresureIn, 2);
                sheet.Rows[rowIndex + 1].Cells[4].Value  =  Decimal.Round((Decimal)(record.PresureOut), 2);
                sheet.Rows[rowIndex + 1].Cells[5].Value  =  Decimal.Round((Decimal)record.WorkingSpeed, 2);
                sheet.Rows[rowIndex + 1].Cells[6].Value  =  Decimal.Round((Decimal)record.Temperature, 2);
                sheet.Rows[rowIndex + 1].Cells[7].Value  =  Decimal.Round((Decimal)(record.WorkingPower/ 1000.0));
                sheet.Rows[rowIndex + 1].Cells[8].Value  =  Decimal.Round((Decimal)(record.WorkingFlow), 2);
                sheet.Rows[rowIndex + 1].Cells[9].Value  =  Decimal.Round((Decimal)(record.WorkingHead), 2);
                sheet.Rows[rowIndex + 1].Cells[10].Value = Decimal.Round((Decimal)(record.Npsh), 2);
                rowIndex++;
            }

            sheet.Rows[55].Cells[2].Value = experiment.CreateTime;
            sheet.Rows[55].Cells[6].Value = experiment.ExperimentOwner;
            sheet.Rows[55].Cells[9].Value = experiment.ExperimentOwner;
            return;
        }
    }
}
